package com.jwthhealth_pub.old.acupressure.view.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.acupressure.module.AcupressureJlpicModule;
import com.jwthhealth_pub.old.acupressure.view.MeridianActivity;
import com.jwthhealth_pub.old.acupressure.view.MeridianInfoActivity;
import com.jwthhealth_pub.old.common.Constant;

import java.util.List;

/**
 * Created by Administrator on 2017/1/12.
 */
public class MeridianAdapter extends RecyclerView.Adapter {

    private MeridianActivity activity;
    private List<AcupressureJlpicModule.DataBean> data;

    public MeridianAdapter(MeridianActivity meridianActivity, List<AcupressureJlpicModule.DataBean> data) {
        this.activity = meridianActivity;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(activity, R.layout.item_meridian, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;

        final AcupressureJlpicModule.DataBean dataBean = data.get(position);

        viewHolder.title.setText(dataBean.getName());

        viewHolder.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(activity, MeridianInfoActivity.class);
                intent.putExtra(Constant.ACUPRESSUREDATA, dataBean);
                activity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        RelativeLayout clickLayout;
        TextView title;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.item_title);
            clickLayout = (RelativeLayout) itemView.findViewById(R.id.click_layout);
        }
    }
}
